package com.fy.tt.entity;

import com.fy.tt.util.JsonUtils;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Data
@NoArgsConstructor
@Table(name = "bls_script")
public class Script {
    //    @TableId(value = "id", type = IdType.AUTO)
    @Id
    @Column(name = "id")
    private Long id;

    //    @ApiModelProperty(value = "剧本名称（可按照剧本功能取名）")
    @Column(name = "name")
    private String name;

    //    @ApiModelProperty(value = "剧本内容（运行剧本的实际内容）")
    @Column(name = "content")
    private String content;

    //    @ApiModelProperty(value = "剧本相关词汇")
    @Column(name = "related_words")
    private List<Long> relatedWords;

    @Column(name = "saver_ids")
    private List<Long> saverIds;
    //    @ApiModelProperty(value = "剧本保存时间")
//    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "save_time")
    private Date saveTime;

    //    @ApiModelProperty(value = "剧本最近（上次）运行时间")
    @Column(name = "last_time")
    private Date lastTime;

    //    @ApiModelProperty(value = "剧本生效状态（0 禁用 1 启用）")
    @Column(name = "type")
    private Long type;

    //    @ApiModelProperty(value = "所属场景区id（ObjBandID）")
    @Column(name = "band_obj_id")
    private Long bandObjId;

    //    @ApiModelProperty(value = "剧本语境定义文本")
    @Column(name = "script_environment")
    private String scriptEnvironment;

    public Script(ResultSet rs) {
        try {
            this.id = rs.getLong("id") ;
            this.name = rs.getString("name");
            this.content = rs.getString("content");

            this.saverIds = JsonUtils.string2Array(rs.getString("saver_ids"));
            this.relatedWords = JsonUtils.string2Array(rs.getString("related_words"));

            this.saveTime = rs.getTimestamp("save_time");
            this.lastTime = rs.getTimestamp("last_time");
            this.type = rs.getLong("type");
            this.bandObjId = rs.getLong("band_obj_id");
            this.scriptEnvironment = rs.getString("script_environment");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }



}
